import { http } from '@/utils/request'

// 登录接口
export interface LoginParams {
  phone: string
  password: string
  remember?: boolean
}

export interface LoginResult {
  token: string
  userInfo: {
    id: number
    phone: string
    nickname: string
    avatar: string
  }
}

// 注册接口
export interface RegisterParams {
  phone: string
  password: string
  code: string
  confirmPassword: string
}

// 发送验证码接口
export interface SendCodeParams {
  phone: string
  type: 'register' | 'reset'
}

// 重置密码接口
export interface ResetPasswordParams {
  phone: string
  code: string
  password: string
  confirmPassword: string
}

// 登录
export const login = (data: LoginParams) => {
  return http.post<LoginResult>('/api/auth/login', data)
}

// 注册
export const register = (data: RegisterParams) => {
  return http.post<void>('/api/auth/register', data)
}

// 发送验证码
export const sendCode = (data: SendCodeParams) => {
  return http.post<void>('/api/auth/send-code', data)
}

// 重置密码
export const resetPassword = (data: ResetPasswordParams) => {
  return http.post<void>('/api/auth/reset-password', data)
}

// 第三方登录
export const thirdPartyLogin = (type: 'wechat' | 'qq', code: string) => {
  return http.post<LoginResult>('/api/auth/third-party-login', { type, code })
}

// 退出登录
export const logout = () => {
  return http.post<void>('/api/auth/logout')
}
